
app.controller('chongzhiCtrl', ['$scope', function ($scope) {
	
	AQ.callAQ("getCzZfb.do", null, function(result) {
		$scope.$apply(function () {
			$scope.zfbData = result[1];
		});
	}, function(err, code) {
		Utils.msgDialog(err + "["+ code +"]");
	});
	
	/*
	获取用户信息
	*/
	AQ.callAQ("refreshUserInfo.do", null, function(result) {
		$scope.User = result[1];
		$.cookie("userName", result[1].userName, {expires: 30});
		$.cookie("User", JSON.stringify(result[1]));
	}, function(err, code){
		Utils.msgDialog(err + "["+ code +"]");
	});

}]);



$(document).ready(function() {
	
	$(".pay-pic1").click(function(e) {
        $("#pay1-box").show();
		$("#pay2-box").hide();
    });
	$(".pay-pic2").click(function(e) {
        $("#pay2-box").show();
		$("#pay1-box").hide();
    });
	$(".to-pay2-type").click(function(e) {
        $("#pay2-box").show();
		$("#pay1-box").hide();
    });
	
	$(".pay1-cz-bt").click(function(e) {
		var payAmount = $.trim($(".pay1-jine").val());
		var amountReg = /^[0-9]{1,5}\.{0,1}[0-9]{0,2}$/;
		if(!amountReg.test(payAmount)) {
			Utils.msgDialog("请输入正确的充值金额！如：100");
			return;
		}
		var idReg = /^user:[0-9]{5,8}$/;
		if(!idReg.test($("input[name='title']").val())) {
			try {
				var User = $.parseJSON($.cookie('User'));
				$("input[name='title']").val("user:"+User.userId);
			} catch(e) { console.log("已知异常："+e); }
			//多次检测“付款说明”，确保绝对正确
			if(!idReg.test($("input[name='title']").val())) {
				AQ.callAQ("refreshUserInfo.do", null, function(result) {
					$("input[name='title']").val("user:"+result[1].userId);
					$.cookie("userName", result[1].userName, {expires: 30});
					$.cookie("User", JSON.stringify(result[1]));
				}, function(err, code){
					Utils.msgDialog(err + "["+ code +"]");
				});
			}
		}
		
		$("input[name='payAmount']").val(payAmount);
		$("#to-cz-fill form").submit();
		
		Utils.checkDialog('<span style="font-weight:bold;">请您在新打开的支付宝付款页面完成付款。</span>', 
		"付款成功", "返回", function() {
			location.replace("user-center.html");
		}, function() {});
    });
	
	/**
	 * 查看二维码
	 */
    $(".sao-ma").click(function(e) {
        if($(".er-wei-ma").css("display") == "none") {
			$(".sao-ma").text("扫二维码付款>");
			$(".sao-ma").css("color", "#F00");
			$(".er-wei-ma").css("display", "inline-block");
		} else {
			$(".er-wei-ma").hide();
			$(".sao-ma").text("扫二维码付款");
			$(".sao-ma").css("color", "#099c86");
		}
    });
	
	/* 提交支付宝交易号 */
	$(".yz-pay-no-bt").click(function(e) {
		var tradeNo = $.trim($(".yz-pay-no").val());
		var numReg = /^[0-9]{20,50}$/;
		if(!numReg.test(tradeNo)) {
			Utils.msgDialog("请输入正确的支付宝交易号！");
			return;
		}
		var param = {
			tradeNo: tradeNo,
		};
        AQ.callAQ("verifyTradeNo.do", param, function(result) {
			Utils.msgDialog("成功充值&nbsp;[" + result[0].info + "元]");
			$(".yz-pay-no").val("");
		}, function(err, code) {
			Utils.msgDialog(err + "["+ code +"]");
		});
    });
	
});